<?php

namespace Common\Middleware\WebSocket;


use Common\Helpers\DebugHelper;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Contract\RequestInterface;
use Hyperf\WebSocketServer\Context;
use Psr\Container\ContainerInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;
use Hyperf\WebSocketServer\Context as WebSocketContext;

/**
 * 职责握手前数据
 */
class WsMiddleware implements MiddlewareInterface
{

    /**
     * @var ContainerInterface
     */
    protected ContainerInterface $container;

    /**
     * @var RequestInterface
     */
    #[Inject]
    protected RequestInterface $request;

    /**
     * 授权验证守卫
     *
     * @var string
     */
    private string $guard = 'jwt';

    public function __construct(ContainerInterface $container, RequestInterface $request)
    {
        $this->container = $container;
        $this->request = $request;
    }


    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
    {
        DebugHelper::consoleWrite('中间件-ws');
        return $handler->handle($request);
    }
}